package interceptor;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * Created by Administrator on 2018/6/1 0001.
 */
public class LoginValidator extends Validator {
    @Override
    protected void validate(Controller c) {
        String errorKey = "errmsg";
        if (c.getPara("username").isEmpty()) {
            addError(errorKey, "用户名不能为空");
        }else
            {  if (c.getPara("password").isEmpty()) {
                addError(errorKey, "密码不能为空");
            }else
            validateCaptcha("captcha",errorKey,"验证码不正确");}


    }

    @Override
    protected void handleError(Controller c) {
        c.renderFreeMarker("login.ftl");
    }
}
